/**
* Copyright (C)2001-2099 Zeai.cn All rights reserved.
* E-Mail：supdes#qq.com　QQ:797311
* http://www.zeai.cn
* http://www.yzlove.com
* Last update 2020/08/15 by supdes
*/
var zeaiSlide={
    index:1,
    run:true,
    load:false,
    init:function () {getudata(zeaiSlide.index);},
    animateMove:function (el,val) {
		if(!zeai.empty(val))o('loading').class('on');
		el.css('transform:translateY('+val+'px);');
        var moveTime=setTimeout(function () {
            zeaiSlide.index++;
			getudata(zeaiSlide.index,val);
        },300);
    }
};
function getudata(pp,val){
	var cls;
	if(!zeai.empty(val)){
		if(val>0){
			cls='off_down';
		}else{
			cls='off_up';
		}
	}else{
		cls='off_up';
	}
	zeai.ajax({url:MHOST+'/video_detail'+zeai.ajxext+'submitok=ajax_list&fid='+fid+'&cls='+cls},function(e){
		e = e.split('|QQ797311|');
		fid = e[0];c = e[1];
		if(zeai.empty(c)){
			o('loading').html('<div><i class="ico">&#xe659;</i><span>已经没有了</span></div>');/*return;*/
			setTimeout(function(){zeai.back();},1000);
		}
		var el=o('mbox');el.html('');el.css('transform:translateY('+(-val)+'px);');
		setTimeout(function(){
			if(!zeai.empty(val))o('loading').class(cls);
			el.html(c);el.css('transform:translateY(0px)');
			videoAutoPlay();
		},500);
	});
}
$("#zeaiSlideObj").on("touchstart",function(e) {
	zeaiSlide.top_val=0;
    if(!zeaiSlide.load || !zeaiSlide.run){return;}
    var ev = e || window.event;
    zeaiSlide._x_start=ev.touches[0].pageX;
    zeaiSlide._y_start=ev.touches[0].pageY;
});
$("#zeaiSlideObj").on("touchmove",function(e) {
    if(!zeaiSlide.load || !zeaiSlide.run){return;}
    var ev = e || window.event;
    zeaiSlide._x_move=ev.touches[0].pageX;
    zeaiSlide._y_move=ev.touches[0].pageY;
    var act_el=o('mbox');
    zeaiSlide.top_val=parseFloat(zeaiSlide._y_move)-parseFloat(zeaiSlide._y_start);
    zeaiSlide.left_val=parseFloat(zeaiSlide._x_move)-parseFloat(zeaiSlide._x_start);
	//act_el.css('transform:translateY('+zeaiSlide.top_val+'px)');
});
$("#zeaiSlideObj").on("touchend",function(e) {
    if(!zeaiSlide.load || !zeaiSlide.run){return;}
    var ev = e || window.event;
    zeaiSlide._x_end=ev.changedTouches[0].pageX;
    zeaiSlide._y_end=ev.changedTouches[0].pageY;
	var zeaiTBdiff=zeaiSlide._y_end-zeaiSlide._y_start;
	var act_el=o('mbox');
    if(zeaiSlide.top_val>0 && zeaiSlide.top_val>doc_height/2-doc_height/4.5){
		//console.log('下');
        zeaiSlide.animateMove(act_el,doc_height);
    }else if(zeaiSlide.top_val<0 && zeaiSlide.top_val<-doc_height/2+doc_height/4.5){
		//console.log('上');
        zeaiSlide.animateMove(act_el,-doc_height);
    }else {
		o('loading').class('on');
    }
});
var doc_height=$(document).height();
$(function (){zeaiSlide.load=true;});
zeaiSlide.init();
zeaiSlide.index++;


function videoAutoPlay(){
	var video=o('video');
	if(video.paused){
		video.play();
		document.addEventListener("WeixinJSBridgeReady", function () {video.play();}, false);
		document.addEventListener('YixinJSBridgeReady', function() {video.play();}, false);
	}else{
		video.pause()
	}
}
function agreeFn (self,fid){
	var em = self.children[0];
	zeai.ajax({url:MHOST+'/video'+zeai.extname,js:1,data:{submitok:'ajax_agree',fid:fid}},function(e){var rs=zeai.jsoneval(e);
		if(rs.flag==1){
			if(!em.hasClass('ed')){
				em.addClass('ed');
				var p=self.lastChild;
				p.html(parseInt(p.innerHTML)+1);
				zeai.msg(rs.msg);
			}
		}
	});
}
function gzFn(self,uid){
	zeai.ajax({url:MHOST+'/u'+zeai.extname,js:1,data:{submitok:'ajax_gz',uid:uid}},function(e){var rs=zeai.jsoneval(e);
		zeai.msg(rs.msg);
		if(rs.flag==1){
			self.addClass('ed');self.html('&#xe6b1; 已关注');
		}else if(rs.flag==0){
			if(self.hasClass('ed'))self.removeClass('ed');
			self.html('&#xe622; 关注');
		}
	});
}